package com.boarsoft.boar.sys.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.common.Constants;
import com.boarsoft.boar.sys.SysParamBiz;
import com.boarsoft.boar.sys.entity.SysParam;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.dao.PagedResult;

@RestController
@RequestMapping("/sys/param")
public class SysParamAction {
	@Autowired
	private SysParamBiz sysParamBiz;
//	@Autowired
//	private ConfigVarSync configVarSync;

	@RequestMapping("/list.do")
	@Authorized(code = "sys.param.list")
	public ReplyInfo<Object> list(String key, String orderBy, int pageNo, int pageSize) {
		PagedResult<SysParam> pr = sysParamBiz.list(key, orderBy, pageNo, pageSize);
		return new ReplyInfo<Object>(true, pr);
	}

	@RequestMapping("/add.do")
	@Authorized(code = "sys.param.add")
	public ReplyInfo<Object> add(SysParam o) {
		if (sysParamBiz.add(o)) {
//			configVarSync.put("sys-param", o.getCode(), o.getValue());
			return ReplyInfo.SUCCESS;
		}
		return Constants.REPLY_INFO_DUPLICATED;
	}

	@RequestMapping("/update.do")
	@Authorized(code = "sys.param.update")
	public ReplyInfo<Object> update(SysParam o) {
		sysParamBiz.update(o);
//		configVarSync.put("sys-param", o.getCode(), o.getValue());
		return ReplyInfo.SUCCESS;
	}

	@RequestMapping("/delete.do")
	@Authorized(code = "sys.param.delete")
	public ReplyInfo<Object> delete(String code) {
		sysParamBiz.delete(code);
//		configVarSync.delete("sys-param", code);
		return ReplyInfo.SUCCESS;
	}

	@RequestMapping("/start.do")
	@Authorized(code = "sys.param.start")
	public ReplyInfo<Object> start(String code) {
		SysParam o = sysParamBiz.start(code);
		if (o == null) {
			return Constants.REPLY_WARN_INVALID;
		}
//		configVarSync.put("sys-param", code, o.getValue());
		return ReplyInfo.SUCCESS;
	}

	@RequestMapping("/stop.do")
	@Authorized(code = "sys.param.stop")
	public ReplyInfo<Object> stop(String code) {
		SysParam o = sysParamBiz.stop(code);
		if (o == null) {
			return Constants.REPLY_WARN_INVALID;
		}
//		configVarSync.delete("sys-param", code);
		return ReplyInfo.SUCCESS;
	}
}